package com.example.kuaizu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.kuaizu.pojo.Certification;
import com.example.kuaizu.pojo.UserProfile;
import com.example.kuaizu.pojo.ov.UserProfileOv;
import com.example.kuaizu.pojo.ov.UserProofOv;
import kuaizu.common.tablepojo.School;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<UserProfile> {
    //插入用户信息
    public int insertUser(UserProfile user);

    /**
     * 根据id查询用户信息
     *
     * @param openid 用户唯一id
     * @return 根据用户唯一id查询用户信息
     * @author xiaokai
     */
    //@Select("select openid,id,phone,nickname,email,school,grade,major,cover_image,avatar_url,gender,age,personality,mbti,persona,project_orientation,introduction,created_at,updated_at  from user_profile where openid = #{openid}")
    UserProfileOv selectUserByAppid(String openid);

    @Select("select * from user_profile where openId = #{openid}")
    UserProfile selectByOpenId(String openid);

    //更细个人信息
    Integer updateUser(UserProfile user);

    @Update("update user_profile set avatar_url = #{avatarUrl} where openid = #{openid}")
    Integer updateUserAvatar(@Param("avatarUrl") String url, @Param("openid") String openid);

    //更新头像
    @Update("update user_profile set cover_image = #{s} where openid = #{openid}")
    void uploadBg(@Param("s") String s, @Param("openid") String openid);

    List<School> selectSchool(String school);

    //添加学校和专业
    @Insert("insert into school_major (school_id,major_name) values (#{school},#{major})")
    void insertMajor(@Param("school") Integer school, @Param("major") Integer major);

    //查询学校和专业
    @Select("select id from school_major where school_id = #{school} and major_name = #{major}")
    Integer selectSchoolMajor(@Param("school") Integer school, @Param("major") Integer major);

    //查询是否有这条学生记录
    @Select("select * from certification where openId = #{openid}")
    Certification selectByOpenidProofInfo(String openid);

    @Update("Update certification set user_photo = #{path} where openId=#{open}")
    void updateUserProofImg(@Param("open") String open, @Param("path") String path);

    //插入一条数据
    void InsterUserProof(Certification certification);

    @Update("Update certification set created_at = #{c.createdAt},certification_info = #{c.certificationInfo} where openId=#{openid}")
    void updateUserProofuserInfoByOpenId(@Param("openid") String openid, @Param("c") Certification certification);

    @Update("update user_profile set certification_info = #{i}  where openId=#{open}")
    void updateUserProoStart(@Param("i") int i, @Param("open") String open);

    //根据学校id查询学校认证信息
    List<UserProofOv> querStudnet(Integer id);
    //删除用户认证信息表中的信息
    @Delete("delete from certification where openId= #{openid}")
    void DelectCertificationInfo(String openId);
    //删除用户信息
    @Delete("delete from user_profile where openId= #{openid}")
    void userOffline(String openId);

    @Select("select * from user_profile where openId = #{openid} And id=#{id}")
    UserProfile selectUserByIdAndOpenId(@Param("id") Integer id,@Param("openid") String openId);
}
